package com.sms.manager;

import java.util.ArrayList;
import com.sms.database.datastore;
import com.sms.model.SMS;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MessageListAdapter extends BaseAdapter{
	
	private ArrayList<SMS> messages;
	private LayoutInflater mInflater;
	Context context;
	
	public MessageListAdapter(Context context,ArrayList<SMS> results){
		messages=results;
		mInflater = LayoutInflater.from(context);
		this.context=context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return messages.size();
		
	}

	@Override
	public Object getItem(int position) {
		return messages.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null){
			holder = new ViewHolder();
			convertView =mInflater.inflate(com.sms.activity.R.layout.messagelistview, null);
			holder.message=(TextView) convertView.findViewById(com.sms.activity.R.id.listitems);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.message.setText(messages.get(position).getMessage());
		System.out.println(messages.get(position).getMessage());
		holder.id=messages.get(position).getId();
		return convertView;
	}
	
	
	static class ViewHolder {
		  String id;   
		  TextView message;
		  
	}

}

